package com.ls.bpmn.dto;

import lombok.Data;
import lombok.NoArgsConstructor;
import com.ls.common.Empty;
import java.util.Date;

/**
 * @Author lisheng
 * @Date 2025/05/07 08:05
 **/
@Data
@NoArgsConstructor
public class ConditionDTO {
    public static final String EQUALS = "eq";
    public static final String NOT_EQUALS = "neq";
    public static final String GREATER_THAN = "gt";
    public static final String GREATER_THAN_OR_EQUALS = "gteq";
    public static final String LESS_THAN = "lt";
    public static final String LESS_THAN_OR_EQUALS = "lteq";
    public static final String LIKE = "like";

    private String name;
    private String operator;
    private Object value;
    private String type;

    public ConditionDTO(String name, String operator, Object value){
        this.name = name;
        this.operator = operator;
        this.value = value;
    }

    public String getType() {
        if(Empty.isNotEmpty(value)){
            if(Empty.isEmpty(type)){
                type = value.getClass().getSimpleName().toLowerCase();
            }
        }

        return type;
    }

    public Object getValue() {
        // 参数类型为boolean时进行值转换
        if(value instanceof Boolean){
            value = (Boolean)value ? 1 : 0;
        }
        // 参数类型为date时进行值转换
        else if(value instanceof Date){
            value = ((Date) value).getTime();
        }

        return value;
    }
}
